import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:memo/state/click_state.dart';
import 'package:memo/state/work_record_state.dart';
import 'package:provider/provider.dart';

class PunchWidget extends StatelessWidget {
  final String text;

  const PunchWidget({Key key, this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Consumer<WorkRecordState>(
          builder: (context, workRecordState, _) => InkWell(
                onTap: () {
                  if ("上" == text) {
                    workRecordState.setMorning();
                  } else {
                    workRecordState.setNight();
                  }
                },
                child: Container(
                  width: 140.0,
                  height: 140.0,
                  alignment: Alignment.center,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Consumer<ClickState>(
                          builder: (context, state, _) => Text(
                              "${DateFormat("HH:mm:ss").format(state.dateTime)}")),
                      const SizedBox(height: 10.0),
                      Text(
                          "$text班打卡",
                          style: TextStyle(
                              fontSize: 18.0, fontWeight: FontWeight.bold)),
                    ],
                  ),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(70.0),
                      color: ThemeData.dark().buttonTheme.colorScheme.primary),
                ),
              ),
        ),
      ],
    );
  }
}
